home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- Custom Def Utils.c
-
- This module contains functions for dealing with xDEF stubs.
- Code was adapted from a post in c.s.m.p '95 about custom MDEFs.
-
- Copyright © 1998, Ammon Skidmore.
-
- ----------------------------------------------------------------------------*/
-
- #include <MixedMode.h>
- #include "Custom Def Utils.h"
-
-
- Handle GetUniversalFunctionHandle(ProcPtr functionAddress,ProcInfoType
- pInfo)
- {
- Handle pHNullProc = NULL;
- ISAType isa;
- UniversalProcPtr axDEFUPP;
-
- isa = GetCurrentISA();
-
- if (isa == kPowerPCISA)
- {
- pHNullProc = NewHandle(sizeof(RoutineDescriptor));
- axDEFUPP = NewRoutineDescriptor(functionAddress,pInfo,isa);
- BlockMove(axDEFUPP, *pHNullProc, sizeof(RoutineDescriptor));
- DisposeRoutineDescriptor(axDEFUPP);
- }
- else
- {
- #pragma unused (pInfo)
-
- pHNullProc = NewHandle(sizeof(JmpInstructionTemplate));
- PatchJmpInstruction(*pHNullProc, (void*)functionAddress);
- }
- return(pHNullProc);
- }
-
-
- void PatchJmpInstruction(void* patchAddress, void* jumpAddress)
- {
- JmpInstructionTemplate* aJmpInstructionPtr;
-
- aJmpInstructionPtr = (JmpInstructionTemplate *) patchAddress;
- aJmpInstructionPtr->Jmp = 0x4EF9;
- aJmpInstructionPtr->Routine = jumpAddress;
- }